package com.heima.controller;

import com.heima.pojo.dto.PartnerDto;
import com.heima.pojo.dto.PartnerSearchDto;
import com.heima.pojo.vo.PartnerSearchVO;
import com.heima.pojo.vo.PartnerVO;
import com.heima.service.PartnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
@Api(tags = "合作商管理相关接口")
@Slf4j
@RequiredArgsConstructor
public class PartnerController {
    private final PartnerService partnerService;

    @PostMapping
    @ApiOperation("新增合作商")
    public Boolean addPartner(@Validated @RequestBody PartnerDto partnerDto) {
        partnerService.addPartner(partnerDto);
        return true;
    }

    @GetMapping("/search")
    @ApiOperation("合作商搜索+分页")
    public PartnerSearchVO pageQuery(PartnerSearchDto partnerSearchDto) {
        return partnerService.pageQuery(partnerSearchDto);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取合作商详情")
    public PartnerVO findById(@PathVariable Integer id) {
        return partnerService.findById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改合作商")
    public Boolean updatePartner(@PathVariable Integer id, @Validated @RequestBody PartnerDto partnerDto) {
        partnerService.updatePartner(id, partnerDto);
        return true;
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除合作商")
    public Boolean delById(@PathVariable Integer id) {
        partnerService.delById(id);
        return true;
    }

    @PutMapping("/resetPwd/{id}")
    @ApiOperation("重置合作商密码")
    public Boolean resetPwd(@PathVariable Integer id) {
        partnerService.resetPwd(id);
        return true;
    }

}
